<template>
  <div id="Conegeometry"></div>
</template>

<script setup lang="ts">
import { onMounted, render } from 'vue'
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'

const scene = new THREE.Scene()

/**
 * 圆锥体的参数
 * @param radius 圆锥体底部半径
 * @param height 圆锥体高度
 * @param radialSegments 圆锥体底部圆的分段数
 * @param heightSegments 圆锥体高度分段数
 * @param openEnded 是否开口
 * @param thetaStart 圆锥体底部圆的起始角度
 * @param thetaLength 圆锥体底部圆的结束角度
 */
const geometry = new THREE.ConeGeometry(5, 20, 30, 10, true, 75)

const humbleMaterial = new THREE.MeshBasicMaterial({
    color: 'white',
    wireframe: true
})
const solidMaterial = new THREE.MeshBasicMaterial({
  color: '#2b7098',
  transparent: true,
  opacity: 0.8
})

const humbelMesh = new THREE.Mesh(geometry, humbleMaterial)
const solidMesh = new THREE.Mesh(geometry, solidMaterial)
scene.add(humbelMesh)
scene.add(solidMesh)

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.z = 20

const renderer = new THREE.WebGLRenderer(camera, humbelMesh)
renderer.setSize(window.innerWidth, window.innerHeight)

const animate = () => {
    requestAnimationFrame(animate)
    humbelMesh.rotation.x += 0.006
    humbelMesh.rotation.y += 0.006
    humbelMesh.rotation.z += 0.006
    solidMesh.rotation.x += 0.006
    solidMesh.rotation.y += 0.006
    solidMesh.rotation.z += 0.006
    renderer.render(scene, camera)
}

onMounted(() => {
    new OrbitControls(camera ,renderer.domElement)
    document.getElementById('Conegeometry')?.appendChild(renderer.domElement)
    animate()
})

window.onresize = () => {
    renderer.setSize(window.innerWidth, window.innerHeight)
    camera.aspect = window.innerWidth / window.innerHeight
    camera.updateProjectionMatrix()
}
</script>

<style>

</style>